package com.nlx.notes.module.mapper.loan;

import com.nlx.notes.module.bean.bo.LoanOverviewBO;
import com.nlx.notes.module.bean.bo.LoanSummaryBO;
import com.nlx.notes.module.bean.dto.loan.LoanSummaryQueryDTO;
import com.nlx.notes.module.bean.dto.loan.RepayDetailSaveDTO;
import com.nlx.notes.module.bean.vo.loan.LoanSummaryVO;
import com.nlx.notes.module.entity.LoanSummary;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author nlx
 * @since 2025-10-25
 */
public interface LoanSummaryMapper extends BaseMapper<LoanSummary> {

    long countByCondition(LoanSummaryQueryDTO loanSummaryQueryDTO);

    List<LoanSummaryBO> pageByCondition(LoanSummaryQueryDTO loanSummaryQueryDTO);

//    @Select(" select * from loan_summary where  borrower_id = #{borrowerId} and loan_status = #{status} and user_id = #{userId} limit 1")
    LoanSummary findByBorrowerIdAndStatus(@Param("borrowerId") Long borrowerId, @Param("status") List<String> status, @Param("userId") Long userId);

    @Update(" update  loan_summary set total_loan = total_loan + #{amount}, remain_amount = remain_amount + #{amount},last_loan_date = #{loanDate} where id = #{id}")
    boolean incTotalLoan(@Param("amount") Integer amount, @Param("loanDate") LocalDate loanDate, @Param("id") Long id);

    LoanOverviewBO sumLoan(LoanSummaryQueryDTO loanSummaryQueryDTO);

    boolean saveRepay(RepayDetailSaveDTO repayDetailSaveDTO);
}
